package com.zsrt.java.day20161226.zzm.demo04;

import java.util.Scanner;

public class SortTest {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			System.out.println("请输入一个不大于5位数");
			int num = sc.nextInt();
			aa(num);
			System.out.println("继续输入请按c,退出请按y");
			String temp = sc.next();
			if(temp.equals("y")){
				System.out.println("程序已经退出....");
				break;
			}
		}
		sc.close();
		
	}
	public static void aa(int a){
		
		int[] arrays = new int[4]; 
		if(a>9999||a<0){
			System.out.println("请输入一个0~99999的数......");
		}else if(a/1000>=1){
			int g=geWei(a);
			arrays[0] = g;
			int s=shiWei(a);
			arrays[1] = s;
			int b=baiWei(a);
			arrays[2] = b;
			int q=qianWei(a);
			arrays[3] = q;
			System.out.println("这是一个四位数......");
			System.out.println("每位数分别为："+q+","+b+","+s+","+g);
			sort(arrays);
		}else if(a/100>=1){
			int g=geWei(a);
			arrays[0] = g;
			int s=shiWei(a);
			arrays[1] = s;
			int b=baiWei(a);
			arrays[2] = b;
			System.out.println("这是一个三位数......");
			System.out.println("每位数分别为："+b+","+s+","+g);
			sort(arrays);
		}else if(a/10>=1){
			int g=geWei(a);
			arrays[0] = g;
			int s=shiWei(a);
			arrays[1] = s;
			System.out.println("这是一个两位数......");
			System.out.println("每位数分别为："+s+","+g);
			sort(arrays);
		}else{
			int g=geWei(a);
			arrays[0] = g;
			System.out.println("这是一个小于10的个位数......");
			System.out.println("每位数分别为："+g);
			sort(arrays);
		}
		
	}
	
	public static int geWei(int num){
		int gewei = num%10;
		return gewei;
	}
	public static int shiWei(int num){
		int shiwei = num%100/10;
		return shiwei;
	}
	public static int baiWei(int num){
		int baiwei = num%1000/100;
		return baiwei;
	}
	public static int qianWei(int num){
		int qianwei = num%10000/1000;
		return qianwei;
	}
	
	public static void sort(int[] arrays){
		System.out.print("逆序输出每个数为:");
		for(int i=0;i<=arrays.length-1;i++){
			if(i==arrays.length-1){
				System.out.print(arrays[i]);
			}else{
				System.out.print(arrays[i]+",");
			}
		}
		System.out.println();
		
	}
}
